<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">短剧推广</a>
            <a><cite>自定义收费模板</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">充值模板名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入充值模板名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="recharge" lay-filter="recharge"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
        {{#  
            if(is_distributor !== 1 && is_branch_office_manage!==1){
                return `
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
                </div>`
            }
        }}
    </script>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="copy">复制</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        {{#  
            if(is_distributor !== 1 && is_branch_office_manage!==1){
                return `
                <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="copy">复制</a>
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>`
            }else{
                return `
                <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="copy">复制</a>
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                `
            }
        }}
    </script>
    <script>
        let params = {
            elem: '#recharge'
            , toolbar: true
            , url: '/cps/recharge/list' //数据接口
            , id: 'recharge'
            , page:true
            , limit:15
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 80, sort: true, align:'center' }
                , { field: 'name', title: '充值模板名称', align:'center', width: 160 }
                // , { field: 'type', title: '充值模板名称', align:'center', width: 160 }
                , {title: '充值模板类型', templet: function (d) {
                        return d.type == 1 ? '低充' : d.type == 2 ? '中充' : '高充'
                    }, align:'center', width: 120 
                }
                , { field: 'responsibility_person_name', title: '负责人', align:'center', width: 100 }
                , { field: 'link_ids', title: '使用链接', align:'center', width: 200 }
                , { field: 'recharged_content', title: '已充值用户', align:'center' }
                , { field: 'not_recharged_content', title: '未充值用户', align:'center' }
                , {
                    field: 'created_at', title: '创建时间', align:'center', width: 170, templet: function (d) {
                        return dayjsFormat(d.created_at) 
                    }
                }
                , { field: 'updated_at', title: '更新时间', width: 170, align:'center', templet: function (d) {
                        return dayjsFormat(d.updated_at)
                    }
                }
                , { toolbar: '#tbBar', align:'center', title: '操作', width: 180 }
            ]]
        }
        tableList(params)

        layui.use('table', function () {
            var table = layui.table;
            table.on('toolbar(recharge)', function (obj) {
                var event = obj.event;
                if (event === 'add') {
                    x_admin_show('添加', './info.html', 1250, 650);
                    // sessionStorage.clear()
                    sessionStorage.removeItem('recharged_content')
                    sessionStorage.removeItem('not_recharged_content')
                    sessionStorage.removeItem('message')
                }
            });
            table.on('tool(recharge)', function (obj) {
                var event = obj.event;
                if (event === 'del') {
                    DeleteAjax('/cps/recharge/delete',{ id: obj.data.id },'recharge')
                } else if (event === 'edit') {
                    x_admin_show('编辑', `./info.html?company_id=${obj.data.company_id}&id=${obj.data.id}`, 1250, 650);
                    // sessionStorage.clear()
                    sessionStorage.removeItem('recharged_content')
                    sessionStorage.removeItem('not_recharged_content')
                    sessionStorage.removeItem('message')
                } else if (event === 'copy'){
                    let {name,type,not_recharged_content,recharged_content} = obj.data;
                    AnyAjax('确定要复制该模板吗？','/cps/recharge/add',{name,type,not_recharged_content,recharged_content},'recharge')
                }
            });

        });
        

    </script>
</body>

</html>